IceCastUpdater = new Class({
	title: '',
	el: Class.empty,
	active: false,
	
	initialize: function(id, el) {
		this.id = id;
		this.el = el;
		this.update.periodical(5000, this);
	},

	update: function() {
		var t = this;
		if (this.active) return;
		this.active = true;
		var myAjax = new Ajax(siteroot + '/modules/mod_icecast/ajax.php?id=' + this.id + '&ts=' + $time(), {
			method: 'get',
			onComplete: function(response) {
				t.active = false;
				var result = Json.evaluate(response);

				$ES('.icecast-song', t.el).setText(result.title);
				$ES('.icecast-listeners', t.el).setText(result.listeners);
			}
		}).request();
	}
});
window.addEvent('domready', function() {
	$$('.icecast_title').each(function(el) {
		new IceCastUpdater(el.getText(), el.getParent());
	});
});
